/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CustomerSearchCondition;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.manager.ExportManager;
/*     */ import com.newcrm.util.MD5;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ExportCustomer extends AbstractAction
/*     */ {
/*  32 */   private static Logger logger = Logger.getLogger(ExportCustomer.class
/*  33 */     .getName());
/*     */ 
/*  66 */   private String filePath = null;
/*     */ 
/*     */   public ExportCustomer(AbstractHttpServlet servlet, String filePath)
/*     */   {
/*  74 */     super(servlet);
/*  75 */     this.filePath = filePath;
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  84 */     User user = super.getLoginUser(request);
/*     */ 
/*  86 */     if (!user.isCanExport()) {
/*  87 */       super.showErrorMessage(response, 
/*  88 */         "您没有导出客户的权限");
/*  89 */       return;
/*     */     }
/*     */ 
/*  92 */     String ip = Util.getClientIpAddr(request);
/*  93 */     logger.warn("ip:" + ip + " / 用户Id：" + user.userId + " /  用户名：" + 
/*  94 */       user.name + ", 进行了导出操作 ");
/*     */ 
/*  96 */     CustomerSearchCondition searchCondition = new CustomerSearchCondition(
/*  97 */       request, user, false);
/*     */ 
/*  99 */     if (ExportManager.getInstance(this.filePath).isExist(searchCondition)) {
/* 100 */       super.showErrorMessage(response, "您的导出请求，在导出队列中已经存在");
/* 101 */       return;
/*     */     }
/*     */ 
/* 104 */     int totalNums = Util.getURLIntParameter(request
/* 105 */       .getParameter("TotalNums"));
/* 106 */     String fileName = MD5.getMD5(new StringBuilder(String.valueOf(user.userId)).append(System.currentTimeMillis()).toString()) + 
/* 107 */       ".xls";
/* 108 */     ExportThread thread = new ExportThread(user, totalNums, 
/* 109 */       searchCondition, this.filePath, fileName);
/* 110 */     thread.start();
/* 111 */     response.setContentType("text/html;charset=utf-8");
/* 112 */     PrintWriter out = response.getWriter();
/* 113 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/* 115 */     jsonObject.put("error", "0");
/* 116 */     out.println(jsonObject);
/* 117 */     out.flush();
/* 118 */     out.close();
/*     */   }
/*     */ 
/*     */   static class ExportThread extends Thread
/*     */   {
/*     */     private int totalNum;
/*     */     private User user;
/*     */     private CustomerSearchCondition searchCondition;
/*     */     private String folder;
/*     */     private String fileName;
/*     */ 
/*     */     public ExportThread(User user, int totalNum, CustomerSearchCondition searchCondition, String folder, String fileName)
/*     */     {
/*  52 */       this.totalNum = totalNum;
/*  53 */       this.user = user;
/*  54 */       this.searchCondition = searchCondition;
/*  55 */       this.folder = folder;
/*  56 */       this.fileName = fileName;
/*     */     }
/*     */ 
/*     */     public void run() {
/*  60 */       ExportManager manager = ExportManager.getInstance(this.folder);
/*  61 */       manager.addTask(this.user, this.searchCondition, this.fileName, 
/*  62 */         this.totalNum);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ExportCustomer
 * JD-Core Version:    0.6.1
 */